#include "client.h"
#include "my_head.h"
#include "protocol.h"
#include<shadow.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
int login(int netfd,char *buf){
    TLVMsg msg;
    char auf[MAX_DETAIL_LEN]={0};
    int len;
    printf("请输入密码:\n");
    read(STDIN_FILENO,buf,sizeof(buf));
    struct spwd* user_info=getspnam(buf);
    ERROR_CHECK(user_info,NULL,"getspnam");
    transmit(netfd,0,strlen(user_info->sp_pwdp),user_info->sp_pwdp);
    recvfd(netfd,&msg);
    return 0;
}
int interface(){
    printf("----------------欢迎使用山寨客户端--------------------------------\n");
    printf("1.cd(切换目录)------------------------------------------后接目录名\n");
    printf("2.ls(列出目录下文件)------------------------------------后啥都不接\n");
    printf("3.puts(上传文件)----------------------------------------后接文件名\n");
    printf("4.gets(下载文件)----------------------------------------后接文件名\n");
    printf("5.remove(删除文件)--------------------------------------后接文件名\n");
    printf("6.pwd(显示当前目录)---------------------------------------后接空气\n");
    printf("7.mkdir(创建目录)---------------------------------------后接目录名\n");
    printf("8.rmdir(创建目录)---------------------------------------后接目录名\n");
    printf("9.login(退出登录)-------------------------------------------------\n");
    printf("10.logout(登录退出)----- --------------------------------------------!\n");
    printf("11.resume(断点续传)----- --------------------------------------------!\n");
    printf("12.quit客户端退出----- --------------------------------------------!\n");
    printf("13.rmdie(删除目录)----- --------------------------------------------!\n");
    return 0;
} 
int enter(int netfd){
    char buf[MAX_PATH_LEN]={0};
    read(STDIN_FILENO,buf,sizeof(buf));
    buf[strlen(buf)]='\0';
    printf("%s\n",buf);
    transmit(netfd,8,strlen(buf),buf);
    printf("请输入密码:\n");
    bzero(buf,sizeof(buf));
    read(STDIN_FILENO,buf,sizeof(buf));
    buf[strlen(buf)]='\0';
    transmit(netfd,8,strlen(buf),buf);
    
    TLVMsg msg;
    recvfd(netfd,&msg);
    if(msg.type==8){
        printf("%s\n",msg.value);
        return 1;
    }
    printf("%s\n",msg.value);
    return 0;
}


